package com.oa.user.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import com.oa.oaspccommon.po.User;
import com.oa.user.mapper.UserMapper;
import com.oa.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zd
 * @date 2021年04月16日 10:39
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public User findOne(Integer uid) {
        return userMapper.findOne(uid);
    }

    @Override
    public int addUser(User user) {
        try {
            userMapper.addUser(user);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int delUser(Integer uid) {
        try {
            userMapper.delUser(uid);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateUser(User user) {
        try {
            userMapper.updateUser(user);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<User> findByLike(String username) {
        return userMapper.findByLike(username);
    }

    @Override
    public PageInfo<User> findByPage(User user, int pageCount, int pageSize) {
        PageHelper.startPage(pageCount,pageSize);
        List<User> users = userMapper.findByPage(user,pageCount,pageSize);
        return new PageInfo<>(users);
    }
}
